package cn.jane.bigevent.service.impl;

import cn.jane.bigevent.entity.Category;
import cn.jane.bigevent.mapper.CategoryMapper;
import cn.jane.bigevent.service.CategoryService;
import cn.jane.bigevent.util.ThreadLocalUtil;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl implements CategoryService {

    private final CategoryMapper categoryMapper;

    public CategoryServiceImpl(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public void add(Category category) {
        category.setCreateUser(ThreadLocalUtil.getUserId());
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.add(category);
    }

    @Override
    public List<Category> list() {
        return categoryMapper.list(ThreadLocalUtil.getUserId());
    }

    @Override
    public Category findById(int id) {
        return categoryMapper.findById(id);
    }

    @Override
    public void update(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.update(category);
    }

    @Override
    public void delete(int id) {
        categoryMapper.delete(id);
    }
}
